package com.Arsanesia.TempleRush.Views.Screens.Components.PopUp;

import java.util.HashMap;

import com.Arsanesia.TempleRush.Enumeration.GeenieEnumeration;
import com.Arsanesia.TempleRush.Views.Screens.AbstractScreen;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.graphics.g2d.BitmapFont.TextBounds;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;

public class Tutorial {
	public static final String NORMAL1_KEY = "NORMAL1";
	public static final String NORMAL2_KEY = "NORMAL2";
	private final String HELP = "help";
	private float x,y;
	private Image tutorialImage;
	private HashMap<String, TextureRegion> tutorialRegion;
	private StringBuffer messagebuffer;
	public Tutorial(TextureAtlas atlas){
		tutorialRegion = new HashMap<String, TextureRegion>();
		//cache all tutorial
		tutorialRegion.put(NORMAL1_KEY, new TextureRegion(atlas.createSprites(HELP).first()));
		tutorialRegion.put(NORMAL2_KEY, new TextureRegion(atlas.createSprites(HELP).get(1)));
		tutorialRegion.put(GeenieEnumeration.BLACK.name(), 
				new TextureRegion(atlas.createSprite(HELP+GeenieEnumeration.BLACK.name())));
		tutorialRegion.put(GeenieEnumeration.WHITE.name(), 
				new TextureRegion(atlas.createSprite(HELP+GeenieEnumeration.WHITE.name())));
		tutorialRegion.put(GeenieEnumeration.GOLD.name(), 
				new TextureRegion(atlas.createSprite(HELP+GeenieEnumeration.GOLD.name())));
		tutorialRegion.put(GeenieEnumeration.GREY.name(), 
				new TextureRegion(atlas.createSprite(HELP+GeenieEnumeration.GREY.name())));
		x=0;
		y=0;
	}
	public void startTutorial(GeenieEnumeration geenie){
		if(geenie == GeenieEnumeration.WHITE || geenie == GeenieEnumeration.GOLD){
			messagebuffer = new StringBuffer("TAP IT \n TO POWER UP!!");
		}else if(geenie == GeenieEnumeration.BLACK){
			messagebuffer = new StringBuffer("DANGER! TAP IT !");
		}else if(geenie == GeenieEnumeration.GREY){
			messagebuffer = new StringBuffer("DANGER! \n\nDON'T TAP IT");
		}else {
			messagebuffer = new StringBuffer();
		}
		
		String key = (geenie.ordinal()<GeenieEnumeration.WHITE.ordinal())?  NORMAL2_KEY: geenie.name();
		tutorialImage = new Image(new TextureRegionDrawable(new TextureRegion(tutorialRegion.get(key))));
		y = (AbstractScreen.VIEWPORT_DEFAULTHEIGHT - tutorialImage.getHeight())/2;
		x = (AbstractScreen.VIEWPORT_DEFAULTWIDTH - tutorialImage.getWidth())/2;
		tutorialImage.setPosition(x, y);
		tutorialImage.addAction(Actions.alpha(1,0.5f));
	}
	
	public void draw(SpriteBatch sb, BitmapFont font){
		tutorialImage.draw(sb, tutorialImage.getColor().a);
		TextBounds messagebound = font.getBounds(messagebuffer);
		font.drawMultiLine(sb, messagebuffer, 
				  (AbstractScreen.VIEWPORT_DEFAULTWIDTH - messagebound.width)/2,
				  AbstractScreen.VIEWPORT_DEFAULTHEIGHT - messagebound.height);
	}

	
}
